package com.jy.study;

import cn.hutool.core.date.*;
import com.sun.org.apache.xerces.internal.dom.PSVIAttrNSImpl;

import java.awt.color.ProfileDataException;
import java.util.Calendar;
import java.util.Date;

/**
 * @Classname HutoolDateUtil
 * @Description hutool工具集之DateUtil
 * @Date 2019/9/17 16:53
 * @Created by  jiaoyong
 */
public class HutoolDateUtil {
    public static void main(String[] args) {
        //当前时间:date = 2019-09-17 16:59:23
        Date date = DateUtil.date();
        //当前时间:date2 = 2019-09-17 16:59:23
        Date dates2 = DateUtil.date(Calendar.getInstance());
        //当前时间:date3 = 2019-09-17 16:59:23
        Date dates3 = DateUtil.date(System.currentTimeMillis());
        //当前时间字符串:now = 2019-09-17 16:59:23
        String now = DateUtil.now();
        //当前日期字符串:today = 2019-09-17
        String today = DateUtil.today();

        Date date1 = DateUtil.parse("2019-09-17");
        Date date2 = DateUtil.parse("2019-09-17", "yyyy-MM-dd");
        Date date3 = DateUtil.parse("2019/09/17", "yyyy/MM/dd");
        Date date4 = DateUtil.parse("2019:09:17", "yyyy:MM:dd");
//        System.out.println("date1 = " + date1);
//        System.out.println("date2 = " + date2);
//        System.out.println("date3 = " + date3);
//        System.out.println("date4 = " + date4);

        //获得年的部分
        int year = DateUtil.year(date);
        //获得月份，从0开始计数
        int month = DateUtil.month(date);
        //获得月份枚举
        Month monthEnum = DateUtil.monthEnum(date);
//        System.out.println("year = " + year);
//        System.out.println("month = " + month);
//        System.out.println("monthEnum = " + monthEnum);

        //结果：2017-03-03 22:33:23
        Date newDate = DateUtil.offset(date, DateField.DAY_OF_MONTH, 2);

//常用偏移，结果：2017-03-04 22:33:23
        DateTime newDate2 = DateUtil.offsetDay(date, 3);

//常用偏移，结果：2017-03-01 19:33:23
        DateTime newDate3 = DateUtil.offsetHour(date, -3);
//        System.out.println("date = " + date);
//        System.out.println("newDate = " + newDate);
//        System.out.println("newDate2 = " + newDate2);
//        System.out.println("newDate3 = " + newDate3);
        Date date5 = DateUtil.parse("2019-09-20 17:35:35");

        Date date6 = DateUtil.parse("2019-09-17 14:35:35");

//相差一个月，31天
        long betweenDay = DateUtil.between(date6, date5, DateUnit.DAY);
        //System.out.println("betweenDay = " + betweenDay);

        //年龄
        int ageOfNow = DateUtil.ageOfNow("1991-01-13");
        //System.out.println("ageOfNow = " + ageOfNow);

//是否闰年
        boolean leapYear = DateUtil.isLeapYear(2019);
        //System.out.println("leapYear = " + leapYear);


        System.out.println(DateUtil.formatDate(DateUtil.yesterday()));
    }
}
